import 'package:flutter/material.dart';
import 'dart:math';

class CustomSliverHeader extends StatelessWidget {
  final double minHeight;
  final double maxHeight;
  final Widget child;
  final bool pinned;
  final bool floating;

  const CustomSliverHeader({
    this.minHeight = 50,
    this.maxHeight = 50,
    @required this.child,
    this.pinned = true,
    this.floating = true,
  });

  @override
  Widget build(BuildContext context) {
    return SliverPersistentHeader(
      delegate: CustomSliverHeaderDelegate(
          minHeight: minHeight, maxHeight: maxHeight, child: child),
      pinned: pinned,
      floating: floating,
    );
  }
}

class CustomSliverHeaderDelegate extends SliverPersistentHeaderDelegate {
  CustomSliverHeaderDelegate({
    @required this.minHeight,
    @required this.maxHeight,
    @required this.child,
  });

  final double minHeight;
  final double maxHeight;
  final Widget child;

  @override
  double get minExtent => minHeight;

  @override
  double get maxExtent => max(maxHeight, minHeight);

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return child;
  }

  @override
  bool shouldRebuild(CustomSliverHeaderDelegate oldDelegate) {
    return true;
  }
}
